code source game Bi-a 3D

23.668 lượt xem;
1 using ThreeDPool.EventHandlers;
2 using
ThreeDPool.Managers;
3
4 namespace
ThreeDPool
5 {
6     
public class Player
7     {
8         
public string Name { private set; get; }
9         
public int Score { private set; get; }
10
11         
public bool HasStrikedBall { private set; get; }
12
13         
private bool _isPlaying;
14
15         
public Player(string name)
16         {
17             
// initializing fields
18             Name = name;
19             Score =
0;
20
21             EventManager.Subscribe(
typeof(CueBallActionEvent).Name, OnCueBallStriked);
22         }
23
24         
private void OnCueBallStriked(object sender, IGameEvent gameEvent)
25         {
26             CueBallActionEvent actionEvent = (CueBallActionEvent)gameEvent;
27             
if (_isPlaying && actionEvent.State == CueBallActionEvent.States.Striked)
28                 HasStrikedBall =
true;
29         }
30
31         
public void SetPlayingState(bool isPlaying)
32         {
33             _isPlaying = isPlaying;
34             HasStrikedBall =
false;
35         }
36
37         
public void CalculateScore(int score)
38         {
39             Score += score;
40
41             
// score will never fo negative
42             
if (Score < 0)
43                 Score =
0;
44
45             EventManager.Notify(
typeof(ScoreUpdateEvent).Name, this, new ScoreUpdateEvent());
46         }
47
48         
public void ResetScore()
49         {
50             Score =
0;
51         }
52     }
53 }


Gõ tìm kiếm nhanh...